﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Dialog.Master" AutoEventWireup="true"
    CodeBehind="RevenueMachineAccountEdit.aspx.cs" Inherits="NetDon.OA.Portal.Finance.RevenueMachineAccountEdit" %>

<%@ Import Namespace="NetDon.Utilities" %>
<%@ Register Src="../Controls/RequiredMark.ascx" TagName="RequiredMark" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script language="javascript" type="text/javascript">

        function calculateRevenueAccount(object) {
            caclualteRevenues();
            caclualteTotalRevenues();
            caclualteProfit();
            caclualteProfitRate();
        }

        function caclualteUnloadingCostWithFactory() {

            var totalGoodsUnloadingPrice = 0;
            $('#<%=this.GridViewOrderDelivery.ClientID %> tr[class*="GridRow"]').each(
                function (row) {
                    var goodsUnloadingPrice = parseFloat($(row).find('td input[id*="txtGoodsUnloadingPriceRatio"]').val());
                    var orderWeight = parseFloat($(row).find('td span[id*="LabelOrderVolumn"]').text());
                    if ($('#<%=txtIsCalculatedByWeight.ClientID %>').val() == 'true') {
                        orderWeight = parseFloat($(row).find('td span[id*="LabelOrderWeight"]').text());

                    }
                    if (goodsUnloadingPrice && orderWeight) {
                        totalGoodsUnloadingPrice += orderWeight * goodsUnloadingPrice;

                    }
                });
            $("#<%=this.txtUnloadingCostWithFactory.ClientID %>").text(totalGoodsUnloadingPrice, 2);
            caclualteTotalRevenues();
            caclualteProfit();
            caclualteProfitRate();
        }

        function caclualteRevenues() {

            var totalRevenues = 0;
            $('#<%=this.GridViewOrderDelivery.ClientID %> tr[class*="GridRow"]').each(
                function (row) {
                    var revenueUnitCost = parseFloat($(row).find('td input[id*="txtRevenueUnitCost"]').val());
                    var orderWeight = parseFloat($(row).find('td span[id*="LabelOrderVolumn"]').text());
                    if ($('#<%=txtIsCalculatedByWeight.ClientID %>').val() == 'true') {
                        orderWeight = parseFloat($(row).find('td span[id*="LabelOrderWeight"]').text());

                    }
                    if (revenueUnitCost && orderWeight) {
                        totalRevenues += orderWeight * revenueUnitCost;

                    }
                });

            $("#<%=this.txtRevenues.ClientID %>").text(totalRevenues, 5);


        }
        function caclualteTotalRevenues() {
            var revenues = parseFloat($("#<%=this.txtRevenues.ClientID %>").text());
            if (!revenues) revenues = 0;
            var subsidy = parseFloat($("#<%=this.txtSubsidy.ClientID %>").val());
            if (!subsidy) subsidy = 0;
            var otherRevenue = parseFloat($("#<%=this.txtOtherRevenue.ClientID %>").val());
            if (!otherRevenue) otherRevenue = 0;

            var carSharingCostWithFactory = parseFloat($("#<%=this.txtCarSharingCostWithFactory.ClientID %>").val());
            if (!carSharingCostWithFactory) carSharingCostWithFactory = 0;

            var unloadingCostWithFactory = parseFloat($("#<%=this.txtUnloadingCostWithFactory.ClientID %>").text());
            if (!unloadingCostWithFactory) unloadingCostWithFactory = 0;
            $("#<%=this.txtTotalRevenues.ClientID %>").text(Math.round(revenues + subsidy + otherRevenue + carSharingCostWithFactory + unloadingCostWithFactory, 5));
        }

        function caclualteProfit() {
            var totalRevenues = parseFloat($("#<%=this.txtTotalRevenues.ClientID %>").text());
            if (!totalRevenues) totalRevenues = 0;
            var cost = parseFloat($("#<%=this.txtCost.ClientID %>").text());
            if (!cost) cost = 0;
            var extraCost = parseFloat($("#<%=this.txtExtraCost.ClientID %>").text());
            if (!extraCost) extraCost = 0;

            $("#<%=this.txtProfit.ClientID %>").text(Math.round(totalRevenues - cost - extraCost, 5));
        }

        function caclualteProfitRate() {
            var profitRate = 0.00;
            var totalRevenues = parseFloat($("#<%=this.txtTotalRevenues.ClientID %>").text());
            if (!totalRevenues) totalRevenues = 0;
            var profit = parseFloat($("#<%=this.txtProfit.ClientID %>").text());
            if (!profit) profit = 0;
            if (totalRevenues != 0) {

                profitRate = (profit * 100 / parseFloat(totalRevenues)).toFixed(2);

            }
            $("#<%=this.txtProfitRate.ClientID %>").text(profitRate.toString() + " %");
        }
        

    </script>
    <style type="text/css">

    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td>
                <NetDon:FormPanel ID="FormPanelStore" runat="server" CaptionAlign="NotSet" RepeatColumns="2"
                    SkinID="ProductView">
                    <Items>
                        <NetDon:FormItem FullRow="True" HeaderVisible="False">
                            <ContentTemplate>
                                <asp:Literal ID="Literal1" runat="server" Text="营收台账"></asp:Literal>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="订单编号">
                            <ContentTemplate>
                                <asp:Label runat="server" ID="txtOrderCode" Text='<%#Bind("OrderCode") %>'>	</asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="出单日期">
                            <ContentTemplate>
                                <asp:Label ID="txtReceivingOrderDate" runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="发货日期">
                            <ContentTemplate>
                                <asp:Label ID="txtAcutalShippingDate" runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="运输计划号">
                            <ContentTemplate>
                                <asp:Label ID="lblTransporationPlanCode" runat="server" Text='<%#Bind("TransportationPlanCode") %>'></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="交货单信息"  FullRow="True">
                            <ContentTemplate>
                                <NetDon:GridView ID="GridViewOrderDelivery" runat="server" AutoGenerateColumns="False"
                                    OnRowDataBound="gridIssuingOrderDelivery_RowDataBound" DataKeyNames="Id" CssClass="IncrementalTable">
                                    <Columns>
                                        <NetDon:IndexField HeaderText="序号">
                                        </NetDon:IndexField>
                                        <NetDon:BoundField Visible="False" DataField="DeliveryCity">
                                        </NetDon:BoundField>
                                        <NetDon:TemplateField HeaderText="交货单号">
                                            <ItemTemplate>
                                                <asp:Label ID="Label12" Text='<%#Eval("DeliveryOrderCode") %>' runat="server"></asp:Label>
                                                <br />
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                        <NetDon:TemplateField HeaderText="送货城市">
                                            <ItemTemplate>
                                                <asp:Label ID="Label13" Text='<%#Eval("DeliveryCityName") %>' runat="server"></asp:Label>
                                                <br />
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                        <NetDon:TemplateField HeaderText="送货地址">
                                            <ItemTemplate>
                                                <asp:Label ID="Label14" Text='<%#Eval("DeliveryAddress") %>' runat="server"></asp:Label>
                                                <br />
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                        <NetDon:TemplateField HeaderText="下单数量">
                                            <ItemTemplate>
                                                <asp:Label ID="LabelOrderQuantity" Text='<%#Convert.ToDecimal(Eval("OrderQuantity")).ToString("#,###.00")%>'
                                                    runat="server"></asp:Label>
                                                <br />
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                        <NetDon:TemplateField HeaderText="下单材积<Br/>（方）">
                                            <ItemTemplate>
                                                <asp:Label ID="LabelOrderVolumn" Text='<%#Convert.ToDecimal(Eval("OrderVolumn")).ToString("#,###.000")%>'
                                                    runat="server"></asp:Label>
                                                <br />
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                        <NetDon:TemplateField HeaderText="下单重量<Br/>（吨）">
                                            <ItemTemplate>
                                                <asp:Label ID="LabelOrderWeight" Text='<%#Convert.ToDecimal(Eval("OrderWeight")).ToString("#,###.000")%>'
                                                    runat="server"></asp:Label>
                                                <br />
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                        <NetDon:TemplateField HeaderText="成本单价">
                                            <ItemTemplate>
                                                <asp:Label ID="LabelUnitCost" Text='<%#Convert.ToDecimal(Eval("UnitCost")).ToString("#,###.0000")%>'
                                                    runat="server"></asp:Label>
                                                <br />
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                        <NetDon:TemplateField HeaderText="营收单价">
                                            <ItemTemplate>
                                                <asp:TextBox ID="txtRevenueUnitCost" Text='<%#Convert.ToDecimal(Eval("RevenueUnitCost")).ToString("#,###.00")%>'
                                                    runat="server" SkinID="Text50" Style="text-align: right"></asp:TextBox>
                                                <NetDon:NumericEditExtender ID="NumericEditExtender7" runat="server" TargetControlID="txtRevenueUnitCost"
                                                    DataMode="Double">
                                                </NetDon:NumericEditExtender>
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                        <NetDon:TemplateField HeaderText="装卸费率">
                                            <ItemTemplate>
                                                <asp:TextBox ID="txtGoodsUnloadingPriceRatio" Text='<%#Convert.ToDecimal(Eval("GoodsUnloadingPriceRatio")).ToString("#,###.00")%>'
                                                    runat="server" SkinID="Text50" Style="text-align: right"></asp:TextBox>
                                                    
                                                <NetDon:NumericEditExtender ID="NumericEditExtender6" runat="server" TargetControlID="txtGoodsUnloadingPriceRatio"
                                                    DataMode="Double">
                                                </NetDon:NumericEditExtender>
                                            </ItemTemplate>
                                        </NetDon:TemplateField>
                                    </Columns>
                                </NetDon:GridView>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <%--    <NetDon:FormItem HeaderText="体积/重量">
                            <ContentTemplate>
                                <asp:Label ID="txtActualEntruckingAmount" runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>--%>
                        <NetDon:FormItem HeaderText="箱数">
                            <ContentTemplate>
                                <asp:Label ID="txtActualEntruckingBoxAmount" runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="下单材积（方）">
                            <ContentTemplate>
                                <asp:Label ID="txtOrdeVolumn" runat="server" SkinID="Text80" Style="text-align: right"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="下单重量（吨）">
                            <ContentTemplate>
                                <asp:Label ID="txtOrderWeight" runat="server" SkinID="Text80" Style="text-align: right"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="下单数量" ColumnSpan="2">
                            <ContentTemplate>
                                <asp:Label ID="txtOrderQuantity" runat="server" SkinID="Text80" Style="text-align: right"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <%--                        <NetDon:FormItem HeaderText="营收单价">
                            <ContentTemplate>
                                <asp:TextBox ID="txtRevenueUnitCost" Text='<%#Convert.ToDecimal(Eval("RevenueUnitCost")).ToString("#,###.00")%>'
                                    runat="server" SkinID="Text80" Style="text-align: right"></asp:TextBox>
                                <uc1:RequiredMark ID="RequiredMark6" runat="server" />
                                <asp:RequiredFieldValidator ID="rfvStoreCode" runat="server" ControlToValidate="txtRevenueUnitCost"
                                    Display="None" ErrorMessage="请输入营收单价" SetFocusOnError="True"></asp:RequiredFieldValidator>
                                <NetDon:NumericEditExtender ID="NumericEditExtender1" runat="server" TargetControlID="txtRevenueUnitCost"
                                    DataMode="Double">
                                </NetDon:NumericEditExtender>
                            </ContentTemplate>
                        </NetDon:FormItem>--%>
                        <NetDon:FormItem HeaderText="成本单价">
                            <ContentTemplate>
                                <asp:Label ID="txtUnitCost" runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="拼车费">
                            <ContentTemplate>
                                <asp:Label ID="txtCarSharingPrice" Text='<%#Convert.ToDecimal(Eval("TotalCarSharingPrice")).ToString("#,###.00")%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="与工厂结的拼车费">
                            <ContentTemplate>
                                <asp:TextBox ID="txtCarSharingCostWithFactory" Text='<%#Convert.ToDecimal(Eval("CarSharingCostWithFactory")).ToString("#,###.00")%>'
                                    runat="server" SkinID="Text80" Style="text-align: right"></asp:TextBox>
                           
                                <NetDon:NumericEditExtender ID="NumericEditExtender2" runat="server" TargetControlID="txtCarSharingCostWithFactory"
                                    DataMode="Double">
                                </NetDon:NumericEditExtender>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="装卸费">
                            <ContentTemplate>
                                <asp:Label ID="txtGoodsUnloadingCost" Text='<%#Convert.ToDecimal(Eval("TotalGoodsUnloadingCost")).ToString("#,###.00")%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="与工厂结的装卸费">
                            <ContentTemplate>
                                <asp:Label ID="txtUnloadingCostWithFactory" Text='<%#Convert.ToDecimal(Eval("UnloadingCostWithFactory")).ToString("#,###.00")%>'
                                    runat="server" SkinID="Text80" Style="text-align: right"></asp:Label>
                                <%--   <uc1:RequiredMark ID="RequiredMark2" runat="server" />
                                <NetDon:NumericEditExtender ID="NumericEditExtender3" runat="server" TargetControlID="txtUnloadingCostWithFactory"
                                    DataMode="Double">
                                </NetDon:NumericEditExtender>--%>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="差方补贴">
                            <ContentTemplate>
                                <asp:TextBox ID="txtSubsidy" Text='<%#Convert.ToDecimal(Eval("Subsidy")).ToString("#,###.00")%>'
                                    runat="server" SkinID="Text80" Style="text-align: right"></asp:TextBox>
                           
                                <NetDon:NumericEditExtender ID="NumericEditExtender4" runat="server" TargetControlID="txtSubsidy"
                                    DataMode="Double" AllowSignal="True">
                                </NetDon:NumericEditExtender>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="其它收入">
                            <ContentTemplate>
                                <asp:TextBox ID="txtOtherRevenue" Text='<%#Convert.ToDecimal(Eval("OtherRevenue")).ToString("#,###.00")%>'
                                    runat="server" SkinID="Text80" Style="text-align: right"></asp:TextBox>
                            
                                <NetDon:NumericEditExtender ID="NumericEditExtender5" runat="server" TargetControlID="txtOtherRevenue"
                                    DataMode="Double">
                                </NetDon:NumericEditExtender>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="营业收入">
                            <ContentTemplate>
                                <asp:Label ID="txtRevenues" Text='<%#Convert.ToDecimal(Eval("Revenues")).ToString("#,###.00")%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="营业总收入">
                            <ContentTemplate>
                                <asp:Label ID="txtTotalRevenues" Text='<%#Convert.ToDecimal(Eval("TotalRevenues")).ToString("#,###.00")%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="成本">
                            <ContentTemplate>
                                <asp:Label ID="txtCost" Text='<%#Convert.ToDecimal(Eval("Cost")).ToString("#,###.00")%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="额外成本">
                            <ContentTemplate>
                                <asp:Label ID="txtExtraCost" Text='<%#Convert.ToDecimal(Eval("ExtraCost")).ToString("#,###.00")%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="利润">
                            <ContentTemplate>
                                <asp:Label ID="txtProfit" Text='<%#Convert.ToDecimal(Eval("Profit")).ToString("#,###.00")%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="毛利率">
                            <ContentTemplate>
                                <asp:Label ID="txtProfitRate" Text='<%#Eval("ProfitRate") +" %"%>' runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="对账否">
                            <ContentTemplate>
                                <%#!MiscUtilities.IsNullOrEmpty(Eval("IsStatementofAccountCompleted")) && Convert.ToBoolean(Eval("IsStatementofAccountCompleted")) ? "是" : "否"%>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="对账日期">
                            <ContentTemplate>
                                <asp:Label ID="txtConfirmStatementofAccountDate" Width="100px" Text='<%#Eval("ConfirmStatementofAccountDate") != null ? ((DateTime)Eval("ConfirmStatementofAccountDate")).ToString("yyyy-MM-dd") : ""%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="应开票日期">
                            <ContentTemplate>
                                <asp:Label ID="Label1" Width="100px" Text='<%#Eval("DueInvoiceDate") != null ? ((DateTime)Eval("DueInvoiceDate")).ToString("yyyy-MM-dd") : ""%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="开票否">
                            <ContentTemplate>
                                <%#!MiscUtilities.IsNullOrEmpty(Eval("IsInvoiced")) && Convert.ToBoolean(Eval("IsInvoiced")) ? "是" : "否"%>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="开票日期">
                            <ContentTemplate>
                                <asp:Label ID="Label2" Width="100px" Text='<%#Eval("ConfirmInvoiceDate") != null ? ((DateTime)Eval("ConfirmInvoiceDate")).ToString("yyyy-MM-dd") : ""%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="应收日期">
                            <ContentTemplate>
                                <asp:Label ID="Label3" Width="100px" Text='<%#Eval("AccountsReceivableDate") != null ? ((DateTime)Eval("AccountsReceivableDate")).ToString("yyyy-MM-dd") : ""%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="收款否">
                            <ContentTemplate>
                                <%#!MiscUtilities.IsNullOrEmpty(Eval("IsAccountsReceivable")) && Convert.ToBoolean(Eval("IsAccountsReceivable")) ? "是" : "否"%>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="收认日期" ColumnSpan="2">
                            <ContentTemplate>
                                <asp:Label ID="Label4" Width="100px" Text='<%#Eval("ConfirmAccountsReceiptDate") != null ? ((DateTime)Eval("ConfirmAccountsReceiptDate")).ToString("yyyy-MM-dd") : ""%>'
                                    runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="未对账备注" ColumnSpan="2">
                            <ContentTemplate>
                                <asp:Label ID="Label5" Text='<%#Eval("UnConfirmStatementofAccountComments")%>' runat="server"></asp:Label>
                            </ContentTemplate>
                        </NetDon:FormItem>
                        <NetDon:FormItem HeaderText="异常情况" FullRow="True">
                            <ContentTemplate>
                                <asp:TextBox ID="txtExceptions" runat="server" Text='<%#Bind("Exceptions") %>' Width="100%"
                                    TextMode="MultiLine" Height="100px"></asp:TextBox>
                            </ContentTemplate>
                        </NetDon:FormItem>
                    </Items>
                </NetDon:FormPanel>
            </td>
        </tr>
        <tr>
            <td style="padding-left: 150px">
                <NetDon:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true"
                    ShowSummary="false" />
               <%--      <asp:Button ID="btnCalculate" runat="server" OnClick="btnCalculate_Click" Text="计算" />--%>
                <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="保存" />
                <asp:Button ID="btnCancel" runat="server" Text="取消" CausesValidation="false" />
                <asp:HiddenField runat="server" ID="txtIsCalculatedByWeight" />
            </td>
        </tr>
    </table>
</asp:Content>
